package com.pea.fow.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.pea.fow.model.Borrow;
import com.pea.fow.service.IBorrowService;
import com.shanlin.jf.model.pay.UserAccount;
import com.shanlin.jf.model.pay.UserAccountLog;
import com.shanlin.jf.service.AutoPayAccountService;



/**
 * @author liyinlong com.pea.fow.controller BorrowController.java
 *         2017年5月11日下午3:46:41
 */
@Controller
@RequestMapping("/v1/borrow")
public class BorrowController {
	private static Logger logger = Logger.getLogger(BorrowController.class);
	@Autowired
	private IBorrowService borrowServiceImpl;
	
	@Autowired
	private AutoPayAccountService autoPayAccountService;

	@RequestMapping(value = "/info", method = RequestMethod.GET)
	//@ResponseBody
	public String toIndex(HttpServletRequest request) {
		
		Borrow borrow = borrowServiceImpl.getBorrowbyBorrowNid("FY-20170214");
		if(borrow != null){
			//request.setAttribute("borrow", borrow);
			request.setAttribute("borrowNid", borrow.getBorrowNid());
			logger.info("borrowNid:"+borrow.getBorrowNid());
		}else{
			request.setAttribute("borrowNid", "borrowNid is null");
			logger.info("borrowNid: is null");
		}
		
		return "borrow";
	}
	@RequestMapping(value = "/info2", method = RequestMethod.GET)
	@ResponseBody
	public String toIndex2(HttpServletRequest request) {
		
		Borrow borrow = borrowServiceImpl.getBorrowbyBorrowNid("FY-20170214");
		if(borrow != null){
			//request.setAttribute("borrow", borrow);
			request.setAttribute("borrowNid", borrow.getBorrowNid());
			logger.info("borrowNid:"+borrow.getBorrowNid());
		}else{
			request.setAttribute("borrowNid", "borrowNid is null");
			logger.info("borrowNid: is null");
		}
		
		return JSON.toJSONString(borrow);
	}
	@RequestMapping(value = "/info3", method = RequestMethod.GET)
	@ResponseBody
	public Borrow toIndex3(HttpServletRequest request) {
		
		Borrow borrow = borrowServiceImpl.getBorrowbyBorrowNid("FY-20170214");
		if(borrow != null){
			//request.setAttribute("borrow", borrow);
			request.setAttribute("borrowNid", borrow.getBorrowNid());
			logger.info("borrowNid:"+borrow.getBorrowNid());
		}else{
			request.setAttribute("borrowNid", "borrowNid is null");
			logger.info("borrowNid: is null");
		}
		
		return borrow;
	}
	@SuppressWarnings("null")
	@RequestMapping(value = "/info4", method = RequestMethod.GET)
	@ResponseBody
	public UserAccount toIndex4(HttpServletRequest request) {
		
		/*utoPayUser user = new AutoPayUser();
		user.setAccountId("610021");
		
		Result re = autoPayUserService.queryRealUser(user);
		System.out.println("re.code:"+re.getCode());*/
		UserAccount userAccount = new UserAccount();
		userAccount = autoPayAccountService.getByUserId("991001");
		
		//UserAccountLog userAccount = autoPayAccountService.getByNid("S271494674824456");
		//System.out.println(userAccount.getAvailableCredit());
		return userAccount;
	}
}
